home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / modelers / chmsthtc / chmsthtc.lzh / Chemesthetics / Source / Source.LZH / _main.c next >
Encoding:
C/C++ Source or Header  |  1991-09-03  |  1.7 KB  |  73 lines

  1. /* ------------------------------------------ */
  2. /*   These are my modified startup routines   */
  3. /* ------------------------------------------ */
  4.  
  5. /* entnommen von QuickReq.c, von FishDisk ??? */
  6.  
  7. /* --------------------- source code revisions, tracked by rcs ---------- */
  8.  
  9. /* $Header: Hard0:C-Compiler/src/routinen/rcs/_main.c,v 1.1 91/08/19 11:19:13 Mtwx Exp Locker: Mtwx $ */
  10. /* $Log:    _main.c,v $
  11.  * Revision 1.1  91/08/19  11:19:13  Mtwx
  12.  * Initial revision
  13.  *  */
  14.  
  15. /* ------------------------------- includes ----------------------------- */
  16.  
  17. #include <exec/types.h>
  18. #include <stdio.h>
  19.  
  20. #define MAXARG 32
  21. #define QUOTE '"'
  22.  
  23. VOID _main(line)
  24. register char *line;
  25. {
  26.     int argc = 0;             /* arg count */
  27.     char *argv[MAXARG];          /* arg pointers */
  28.  
  29.     argc = ParseCommands(0, line, argv);
  30.     if(argc > MAXARG)
  31.       XCEXIT(1);
  32.  
  33.     main(argc, argv);
  34.     XCEXIT(0);
  35. }
  36.  
  37. /* I have separated this to own routine, because I also use this to parse
  38.    redirection file.
  39. */
  40.  
  41. int ParseCommands(int Start, register char *line, char *args[])
  42. {
  43.     register char **pargv;
  44.     int argc;
  45.  
  46.     argc = Start;
  47.  
  48.     while (argc < MAXARG)
  49.     {
  50.     while (isspace(*line))  line++;
  51.     if (*line == '\0')      break;
  52.     pargv = &args[argc++];
  53.     if (*line == QUOTE)
  54.         {
  55.         *pargv = ++line;  /* ptr inside quoted string */
  56.         while ((*line != '\0') && (*line != QUOTE)) line++;
  57.         if (*line == '\0') {
  58.         return(MAXARG+1);
  59.         }
  60.         else        *line++ = '\0';  /* terminate arg */
  61.     }
  62.     else        /* non-quoted arg */
  63.     {
  64.         *pargv = line;
  65.         while ((*line != '\0') && (!isspace(*line))) line++;
  66.         if (*line == '\0')  break;
  67.         else        *line++ = '\0';  /* terminate arg */
  68.     }
  69.     }  /* while */
  70.  
  71.     return(argc);
  72. }
  73.